﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class bgData_Zbmsg : System.Web.UI.Page
{
    string ID = "";
    string sql1 = "";
    string type = "";

    BLL.BLLData bd = new BLLData();

    protected void Page_Load(object sender, EventArgs e)
    {
        type = Request.QueryString["type"];

        if (!IsPostBack)
        {
            if (type == "bj")
            {
                ID = Request.QueryString["ID_KEY"].ToString();

                DataRow dr = bd.retTableRowById(ID);

                this.txtParaName.Text = dr["参数名"].ToString();

                if (dr["小时点"] != null)
                    this.txtHour.Text = dr["小时点"].ToString();

                if (dr["日点"] != null)
                    this.txtDay.Text = dr["日点"].ToString();

                if (dr["月点"] != null)
                    this.txtM.Text = dr["月点"].ToString();

                if (dr["季点"] != null)
                    this.txtJi.Text = dr["季点"].ToString();

                if (dr["年点"] != null)
                    this.txtY.Text = dr["年点"].ToString();

                if (dr["单位"] != null)
                    this.txtUnit.Text = dr["单位"].ToString();

                if (dr["设计值"] != null)
                    this.txtSj.Text = dr["设计值"].ToString();

                if (dr["参数顺序"] != null)
                    this.txtXSSX.Text = dr["参数顺序"].ToString();

                if (dr["参数key"] != null)
                    this.txtKey.Text = dr["参数key"].ToString();

                if (dr["小数点数"] != null)
                    this.txtPoint.Text = dr["小数点数"].ToString();

                if (dr["参数类型"] != null)
                    this.txtType.Text = dr["参数类型"].ToString();

                if (dr["最优值"] != null)
                    this.txtZy.Text = dr["最优值"].ToString();

                if (dr["电量点"] != null)
                    this.txtPower.Text = dr["电量点"].ToString();

                if (dr["显示"] != null && dr["显示"].ToString() != "")
                {
                    if (dr["显示"].ToString() == "1")
                        this.drpShow.SelectedValue = "1";
                    else
                        this.drpShow.SelectedValue = "0";
                }

                if (dr["公式级别"] != null)
                    this.txtLev.Text = dr["公式级别"].ToString();

                if (dr["参数ID"] != null)
                    this.txtParaID.Text = dr["参数ID"].ToString();

                if (dr["公式"] != null)
                    this.txtFormula.Text = dr["公式"].ToString();

                if (dr["公式参数"] != null)
                    this.txtFormPara.Text = dr["公式参数"].ToString();

                if (dr["SQL语句"] != null)
                    this.sql.Text = dr["SQL语句"].ToString();

                this.repName.Text = dr["报表名称"].ToString();

                this.hidID.Value = ID;
                this.hidJZ.Value = dr["机组"].ToString();

                this.txtjz.Text = dr["机组"].ToString();
            }
        }
    }


    protected void addbtn_Click(object sender, EventArgs e)
    {
        if (type == "bj")
        {
            sql1 = "update t_sheet_sheetPara set 参数名='" + this.txtParaName.Text + "',小时点='" + this.txtHour.Text + "',日点='" + this.txtDay.Text + "', 月点='" + this.txtM.Text + "',季点='" + this.txtJi.Text + "', 年点 ='" + this.txtY.Text + "',报表名称='" + this.repName.Text + "',参数顺序=" + this.txtXSSX.Text + " ,单位='" + this.txtUnit.Text + "', 设计值='" + this.txtSj.Text + "',参数类型='" + this.txtType.Text + "',小数点数='" + this.txtPoint.Text + "',最优值='" + this.txtZy.Text + "',电量点='" + this.txtPower.Text + "',显示=" + int.Parse(this.drpShow.SelectedValue) + ", 参数key='" + this.txtKey.Text + "',参数ID='" + this.txtParaID.Text + "', 公式='" + this.txtFormula.Text + "',公式参数='" + this.txtFormPara.Text + "',SQL语句='" + this.sql.Text + "',公式级别=" + int.Parse(this.txtLev.Text) + ",机组=" + int.Parse(this.hidJZ.Value) + " where ID_KEY=" + this.hidID.Value;
        }
        else if (type == "add")
        {
            sql1 = "insert into t_sheet_sheetPara (参数名,小时点,日点,月点,年点,季点,报表名称,参数顺序,机组,单位,设计值,参数类型,小数点数,最优值,电量点,显示,参数key,参数ID,公式,公式参数,SQL语句,公式级别)";

            sql1 += " values ('" + this.txtParaName.Text + "','" + this.txtHour.Text + "','" + this.txtDay.Text + "','" + this.txtM.Text + "','" + this.txtY.Text + "','" + this.txtJi.Text + "','" + this.repName.Text + "'," + this.txtXSSX.Text + "," + this.txtjz.Text + ",'" + this.txtUnit.Text + "','" + this.txtSj.Text + "','" + this.txtType.Text + "','" + this.txtPoint.Text + "','" + this.txtZy.Text + "','" + this.txtPower.Text + "'," + this.drpShow.SelectedValue + ",'" + this.txtKey.Text + "','" + this.txtParaID.Text + "','" + this.txtFormula.Text + "','" + this.txtFormPara.Text + "','" + this.sql.Text + "'," + this.txtLev.Text + ")";
        }


        bool flag = bd.retIsTrueBySQL(sql1);

        if (flag == true)
            Jscript.AlertAndCloseWindow("保存成功!");
        else
            Jscript.Alert("保存失败!");

    }

}
